package com.koron.css2.baseConfig.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.baseConfig.mapper.BaseBookMapper;
import com.koron.css2.baseConfig.vo.BaseBookListVO;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.util.Constant;
import com.koron.util.JsonUtils;
import com.koron.util.ValidationKey;
import org.apache.commons.lang3.StringUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

public class BaseBookAdd implements ServerInterface {

	@Override
	@ValidationKey(clazz = BaseBookListVO.class,method = "insert")
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		// TODO Auto-generated method stub
		try {
			BaseBookMapper mapper = factory.getMapper(BaseBookMapper.class);
			BaseBookListVO bean = JsonUtils.objectToPojo(req.getData(), BaseBookListVO.class);
			if(StringUtils.isBlank(bean.getBookNo())){
				return MessageBean.create(Constant.MESSAGE_INT_FAIL, "册本号不能为空。", void.class);
			}
			if(StringUtils.isBlank(bean.getBookName())){
				return MessageBean.create(Constant.MESSAGE_INT_FAIL, "册本名称不能为空。", void.class);
			}
			bean.setCreateInfo(userInfo);
			mapper.insert(bean);
		} catch (Exception e) {
			logger.error("操作失败", e);
			return MessageBean.create(Constant.MESSAGE_INT_FAIL, "操作失败", void.class);
		}
		return MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", void.class);
	
	}

}
